import java.io.IOException;


public class Communication extends Thread {
	
	private webSocket ws;
	private Tv tv;
	
	public Communication(webSocket ws, Tv tv){
		this.ws = ws;
		this.tv = tv;
	}
	
    private void handleConnection() {
        try {
        	String message = ws.getMessage();
        	if(message.equals("GET")){
        		while (true) {
        			ws.sendMessage("Channel:" + tv.getChannel()+"\nDescription: "+tv.getDescription());
        			Thread.sleep(2000);
        		}
        	}
        } catch (InterruptedException i) {
        }finally {
            ws.close();
        }
    }
	
    public void run() {
    	handleConnection();
    }
   

}
